*::after, *::before {
  box-sizing: border-box;
}

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #222
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--bg);
  gap: 40px;
}

.box {
  position: relative;
  width: 300px;
  height: 300px;
  overflow: hidden;
}

.box.one {
  background: url(./bg1.jpg) no-repeat center;
  background-size: cover;
}

.box.two {
  background: url(./bg2.jpg) no-repeat center;
  background-size: cover;
}

.box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 750px;
  background: linear-gradient(transparent, transparent 300px, var(--bg) 450px, var(--bg) 750px);
  z-index: 2;
  transition: 1s;
}

.box:hover::before {
  top: -450px;
}

.box.two::before {
  top: 0;
  left: 0;
  height: 100%;
  width: 750px;
  background: linear-gradient(90deg, transparent, transparent 300px, var(--bg) 450px, var(--bg) 750px);;
}

.box.two:hover:before {
  top: 0;
  left: -450px;
}